package org.jeecg.modules.demo.drfpapers.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.demo.drfpapers.entity.DrfPapers;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * @Description: 论文表
 * @Author: jeecg-boot
 * @Date:   2025-10-02
 * @Version: V1.0
 */
@Mapper
public interface DrfPapersMapper extends BaseMapper<DrfPapers> {

    @Select("SELECT status FROM drf_papers WHERE student_id = #{Id}")
    String getPaperStatus(String Id);

    /**
     * 修改论文状态
     * @param id
     * @param status
     * @return 更新的行数
     */
    @Update("UPDATE drf_papers SET status = #{status} WHERE id = #{id}")
    int updatePaperStatus(String id, String status);

    @Update("UPDATE drf_papers SET status = #{status} WHERE id = #{id}")
    int updateStatus(String id, String status);

    @Select("SELECT * FROM drf_papers WHERE student_id = #{userId}")
    List<DrfPapers> getPaperByUserId(String userId);

    /**
     * 获取历史论文，先通过查询个人审核任务表要求end_time不为空，获取论文id
     * @param userId
     * @return
     */
    @Select("SELECT * FROM drf_papers WHERE id IN (SELECT papers_id FROM drf_individual_review WHERE end_time IS NOT NULL AND teacher_id = #{userId})")
    List<DrfPapers> getHistoryPapers(String userId);

    /**
     * 通过file_id获取论文
     * @param fileId
     * @return
     */
    @Select("SELECT * FROM drf_papers WHERE file_id = #{fileId}")
    DrfPapers getPaperByFileId(Integer fileId);

//    //获取需要审核的论文数,教师id1或2只要一个满足就可以
//    @Select("SELECT COUNT(*) FROM drf_papers WHERE status = 'pendingReview' AND (teacher_id = #{id} OR teacher_id = #{id})")
//    Integer getNeedReviewCount(String id);
}